'\" et
.TH NOHUP "1P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\"
.SH PROLOG
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
.\"
.SH NAME
nohup
\(em invoke a utility immune to hangups
.SH SYNOPSIS
.LP
.nf
nohup \fIutility \fB[\fIargument\fR...\fB]\fR
.fi
.SH DESCRIPTION
The
.IR nohup
utility shall invoke the utility named by the
.IR utility
operand with arguments supplied as the
.IR argument
operands. At the time the named
.IR utility
is invoked, the SIGHUP signal shall be set to be ignored.
.P
If standard input is associated with a terminal, the
.IR nohup
utility may redirect standard input from an unspecified file.
.P
If the standard output is a terminal, all output written by the named
.IR utility
to its standard output shall be appended to the end of the file
.BR nohup.out
in the current directory. If
.BR nohup.out
cannot be created or opened for appending, the output shall be appended
to the end of the file
.BR nohup.out
in the directory specified by the
.IR HOME
environment variable. If neither file can be created or opened for
appending,
.IR utility
shall not be invoked. If a file is created, the file's permission bits
shall be set to S_IRUSR | S_IWUSR.
.P
If standard error is a terminal and standard output is open but is not
a terminal, all output written by the named utility to its standard
error shall be redirected to the same open file description as the
standard output. If standard error is a terminal and standard output
either is a terminal or is closed, the same output shall instead be
appended to the end of the
.BR nohup.out
file as described above.
.SH OPTIONS
None.
.SH OPERANDS
The following operands shall be supported:
.IP "\fIutility\fR" 10
The name of a utility that is to be invoked. If the
.IR utility
operand names any of the special built-in utilities in
.IR "Section 2.14" ", " "Special Built-In Utilities",
the results are undefined.
.IP "\fIargument\fR" 10
Any string to be supplied as an argument when invoking the utility
named by the
.IR utility
operand.
.SH STDIN
Not used.
.SH "INPUT FILES"
None.
.SH "ENVIRONMENT VARIABLES"
The following environment variables shall affect the execution of
.IR nohup :
.IP "\fIHOME\fP" 10
Determine the pathname of the user's home directory: if the output
file
.BR nohup.out
cannot be created in the current directory, the
.IR nohup
utility shall use the directory named by
.IR HOME
to create the file.
.IP "\fILANG\fP" 10
Provide a default value for the internationalization variables that are
unset or null. (See the Base Definitions volume of POSIX.1\(hy2017,
.IR "Section 8.2" ", " "Internationalization Variables"
for the precedence of internationalization variables used to determine
the values of locale categories.)
.IP "\fILC_ALL\fP" 10
If set to a non-empty string value, override the values of all the
other internationalization variables.
.IP "\fILC_CTYPE\fP" 10
Determine the locale for the interpretation of sequences of bytes of
text data as characters (for example, single-byte as opposed to
multi-byte characters in arguments).
.IP "\fILC_MESSAGES\fP" 10
.br
Determine the locale that should be used to affect the format and
contents of diagnostic messages written to standard error.
.IP "\fINLSPATH\fP" 10
Determine the location of message catalogs for the processing of
.IR LC_MESSAGES .
.IP "\fIPATH\fP" 10
Determine the search path that is used to locate the utility to be
invoked. See the Base Definitions volume of POSIX.1\(hy2017,
.IR "Chapter 8" ", " "Environment Variables".
.SH "ASYNCHRONOUS EVENTS"
The
.IR nohup
utility shall take the standard action for all signals except that
SIGHUP shall be ignored.
.SH STDOUT
If the standard output is not a terminal, the standard output of
.IR nohup
shall be the standard output generated by the execution of the
.IR utility
specified by the operands. Otherwise, nothing shall be written to the
standard output.
.SH STDERR
If the standard output is a terminal, a message shall be written to the
standard error, indicating the name of the file to which the output is
being appended. The name of the file shall be either
.BR nohup.out
or
.BR $HOME/nohup.out .
.SH "OUTPUT FILES"
Output written by the named utility is appended to the file
.BR nohup.out
(or
.BR $HOME/nohup.out ),
if the conditions hold as described in the DESCRIPTION.
.SH "EXTENDED DESCRIPTION"
None.
.SH "EXIT STATUS"
The following exit values shall be returned:
.IP 126 8
The utility specified by
.IR utility
was found but could not be invoked.
.IP 127 8
An error occurred in the
.IR nohup
utility or the utility specified by
.IR utility
could not be found.
.P
Otherwise, the exit status of
.IR nohup
shall be that of the utility specified by the
.IR utility
operand.
.SH "CONSEQUENCES OF ERRORS"
Default.
.LP
.IR "The following sections are informative."
.SH "APPLICATION USAGE"
The
.IR command ,
.IR env ,
.IR nice ,
.IR nohup ,
.IR time ,
and
.IR xargs
utilities have been specified to use exit code 127 if an error occurs
so that applications can distinguish ``failure to find a utility'' from
``invoked utility exited with an error indication''. The value 127 was
chosen because it is not commonly used for other meanings; most
utilities use small values for ``normal error conditions'' and the
values above 128 can be confused with termination due to receipt of a
signal. The value 126 was chosen in a similar manner to indicate that
the utility could be found, but not invoked. Some scripts produce
meaningful error messages differentiating the 126 and 127 cases. The
distinction between exit codes 126 and 127 is based on KornShell
practice that uses 127 when all attempts to
.IR exec
the utility fail with
.BR [ENOENT] ,
and uses 126 when any attempt to
.IR exec
the utility fails for any other reason.
.SH EXAMPLES
It is frequently desirable to apply
.IR nohup
to pipelines or lists of commands. This can be done by placing
pipelines and command lists in a single file; this file can then be
invoked as a utility, and the
.IR nohup
applies to everything in the file.
.P
Alternatively, the following command can be used to apply
.IR nohup
to a complex command:
.sp
.RS 4
.nf

nohup sh -c \(aq\fIcomplex-command-line\fP\(aq </dev/null
.fi
.P
.RE
.SH RATIONALE
The 4.3 BSD version ignores SIGTERM and SIGHUP, and if
.BR ./nohup.out
cannot be used, it fails instead of trying to use
.BR $HOME/nohup.out .
.P
The
.IR csh
utility has a built-in version of
.IR nohup
that acts differently from the
.IR nohup
defined in this volume of POSIX.1\(hy2017.
.P
The term
.IR utility
is used, rather than
.IR command ,
to highlight the fact that shell compound commands, pipelines, special
built-ins, and so on, cannot be used directly.
However,
.IR utility
includes user application programs and shell scripts, not just the
standard utilities.
.P
Historical versions of the
.IR nohup
utility use default file creation semantics. Some more recent versions
use the permissions specified here as an added security precaution.
.P
Some historical implementations ignore SIGQUIT in addition to SIGHUP;
others ignore SIGTERM. An early proposal allowed, but did not require,
SIGQUIT to be ignored. Several reviewers objected that
.IR nohup
should only modify the handling of SIGHUP as required by this volume of POSIX.1\(hy2017.
.P
Historical versions of
.IR nohup
did not affect standard input, but that causes problems in the common
scenario where the user logs into a system, types the command:
.sp
.RS 4
.nf

nohup make &
.fi
.P
.RE
.P
at the prompt, and then logs out. If standard input is not affected by
.IR nohup ,
the login session may not terminate for quite some time, since standard
input remains open until
.IR make
exits. To avoid this problem, POSIX.1\(hy2008 allows implementations to
redirect standard input if it is a terminal. Since the behavior is
implementation-defined, portable applications that may run into the
problem should redirect standard input themselves. For example,
instead of:
.sp
.RS 4
.nf

nohup make &
.fi
.P
.RE
.P
an application can invoke:
.sp
.RS 4
.nf

nohup make </dev/null &
.fi
.P
.RE
.SH "FUTURE DIRECTIONS"
None.
.SH "SEE ALSO"
.IR "Chapter 2" ", " "Shell Command Language",
.IR "\fIsh\fR\^"
.P
The Base Definitions volume of POSIX.1\(hy2017,
.IR "Chapter 8" ", " "Environment Variables"
.P
The System Interfaces volume of POSIX.1\(hy2017,
.IR "\fIsignal\fR\^(\|)"
.\"
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1-2017, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 7, 2018 Edition,
Copyright (C) 2018 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group.
In the event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html .
.PP
Any typographical or formatting errors that appear
in this page are most likely
to have been introduced during the conversion of the source files to
man page format. To report such errors, see
https://www.kernel.org/doc/man-pages/reporting_bugs.html .
